CPP

Section: User Commands (1)
Updated: 30 May 1993
Index Return to Main Contents
 

NAME

cpp - a stand-alone C preprocessor  

SYNOPSIS

cpp [ -CTV ] [ -P[012] ] [ -Dname ]
      [ -Dname=def ] [ -Idirectory ] [ -Uname ]
      [ -ansi ] [ -f[no-]c++-comments ] [ -W[no-]bad-chars ]
      [ -W[no-]nested-comments ] [ -W[no-]bad-concat-tokens ] [ input-file [ output-file ] ]  

DESCRIPTION

cpp is a stand-alone C preprocessor, intended for use with C compilers such as HSC which do not provided access to preprocessor output. It implements as closely as possible an ANSI standard C preprocessor, including trigraphs, token pasting and stringizing.

cpp optionally accepts two filenames as arguments. input-file and output-file are, respectively, the input and output files for the preprocessor. If not specified, or if given as `-', they default to the standard input and the standard output, respectively.  

OPTIONS

-C
Pass all comments (except those that appear on cpp directive lines) through the preprocessor. By default, cpp strips out C-style comments.
-P[012]
Preprocess the input without producing the line control information used by the next pass of the C compiler. A numeric argument can be passed to -P: 0 specifies that no line control information control is generated, and is equivalent to -P; 1 specifies that normal line control information is generated, which is the default; and 2 specifies that line control information is generated in the form of preprocessor #line directives.
-T
Translate trigraphs in the input file. This behavior is implied by the -ansi option.
-D name
Define name as 1 (one). This is the same as if a -Dname=1 option appeared on the cpp command line, or as if a
#define name 1
line appeared in the source file that cpp is processing.
-Dname=def
Define name as if by a #define directive. This is the same as if a
#define name def
line appeared in the source file that cpp is processing. The -D option has lower precedence than the -U option; that is, if the same name is used in both a -U option and a -D option, the name will be undefined regardless of the order of the options.
-Idirectory
Insert directory into the search path for #include files with names not beginning with `/', `\\', or a drive specifier. directory is inserted ahead of the standard list of ``include'' directories. Thus, #include files with names enclosed in double-quotes (") are searched for first in the directory of the file with the #include line, then in directories named with -I options, and lastly, in directories from the standard list. For #include files with names enclosed in angle-brackets (<>), the directory of the file with the #include line is not searched. See USAGE below for exact details of this search order.
-S[filename]
Specify an alternate configuration file. If filename is present, the specified file is read instead of the default configuration file; if filename is absent, the default configuration file is simply not read. See USAGE below for further details.
-Uname
Remove any initial definition of name, where name is a symbol that is predefined by the preprocessor.
-V
Print version information to stderr.
-ansi
Define the preprocessor token __STDC__ to have value 1, and enable trigraph translation. To get __STDC__ without trigraph translation, you can specify the options -ansi -T.

The following -f and -W options can be negated by adding a no- before the option name. Some are on by default.

-fc++-comments
Support the C++ comment indicator `//'. With this option active, everything on the line after the // is treated as a comment. Off by default.
-Wbad-chars
Issue a warning if a character that cannot legally appear in a C program appears in the input. On by default.
-Wnested-comments
Issue a warning if a comment-start character sequence (`/*', and `//' if -fc++-comments is active) appears in a comment. Off by default.
-Wbad-concat-tokens
Issue a warning if the token concatenation operator ## produces an illegal C token. On by default.

Options beginning with -X are for specialized interactions with particular programs, and should not generally be invoked directly by the user. The following such options are currently recognized:

-Xfluff
This option is used by the fluff(1) source code checker. It causes the preprocessor token __FLUFF__ to be defined, and enables certain related pragmas. See the fluff(1) documentation for further information.
 

USAGE

If you are familiar with C, you should already know about the basic workings of cpp. We will not go into a detailed description here, since any good book on C could do better; instead, we will describe details particular to this implementation.  

Directory Search Order

A file specified in an #include directive will be searched for in the following directories, in order:

1.
The directory of the file that contains the #include directive, if the directive is of the form `#include ``filename'''.
2.
The directories specified by -I options, in the order they were specified.
3.
The list of directories specified in the INCLUDE environment variable, in order.
 

Special Names

The following macros are predefined by cpp:

__STDC__
Expands to 1 if the -ansi option is specified.
__LINE__
Expands to an integer constant representing the current line number in the current input file.
__FILE__
Expands to a string constant representing the name of the current input file.
__DATE__
Expands to a string constant of the form "Mmm dd yyyy" representing the date on which preprocessing was initiated.
__TIME__
Expands to a string constant of the form "hh:mm:ss" representing the system time at which preprocessing was initiated.
__INCLUDE_LEVEL__
Expands to an integer constant representing the current depth of nested #include files.
 

Configuration files

cpp uses a configuration file to set up site-specific predefined macros. By default, the directories specified in the LIB environment variable are searched in order for the file cpp_defs.h; an alternate file can be specified from the command line with the -S option.

The configuration file is read just like a normal input file, except that text other than preprocessor directives is not passed through to the output file. Normally the configuration file will contain only comments and preprocessor directives. In addition, two special pragmas are recognized within the configuration file only:

#pragma CPP_cmdline_arg option
The single token option is processed as though it had appeared as a command-line option. The option may be undone from the command line, except as indicated below.
#pragma CPP_delayed
Normally, the configuration file is processed before command-line options are processed, to allow the commands therein to be overridden by command-line options. This pragma causes the command line to be processed before the remainder of the file, allowing conditional setup based on parameters set from the command line. Note that macro definitions and command-line specifications made after this pragma cannot be undone from the command line.

For example, the following configuration file activates C++ comments by default, and sets the macro _PROTO() according to the presence of the -ansi option:

    #pragma CPP_cmdline_arg -fc++-comments
    #pragma CPP_delayed
    #ifdef __STDC__
    #  define _PROTO(x) x
    #else
    #  define _PROTO(x) ()
    #endif

 

SEE ALSO

fluff(1)

Documentation for your C compiler

Any good book on C.
 

DIAGNOSTICS

The error messages produced by cpp are intended to be self-explanatory. The line number and filename where the error occurred are printed along with the diagnostic.  

BUGS

None that I know of, but there's almost always One More Bug(TM). If you should find one, please report it to me, Scott Bigham, at dsb@cs.duke.edu.


 

Index

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
USAGE
Directory Search Order
Special Names
Configuration files
SEE ALSO
DIAGNOSTICS
BUGS

This document was created by man2html, using the manual pages.
Time: 16:09:07 GMT, September 10, 2022